--[[
  测试发现,joypad.get和joypad.read效果一样,读取按键状态表,key是Map game inputs的按键
  但joypad.write和joypad.set虽然参数提示是一个table,但无论怎么搞都没反应!
  即使set完马上get,也是显示全为false.目前只能当它没做好了.
]]

-- 测试joypad.get的返回值,发现是一个表,返回Map game inputs菜单下按键的状态,列入P1 Button 1,未按下为false
function getTest()
  local keyStates
  local k, v
  keyStates = joypad.get()
  for k, v in pairs(keyStates) do
    print(k, v)
  end
end

function setTest(val)
  local keyName, keyStates
  keyStates = joypad.get()
  --keyStates = {}
  keyName = "P1 Button 1"
  if keyStates[keyName] == nil then
    --print("no "..keyName)
    --return
  end
  keyStates[keyName] = val
  --keyStates["Up"] = 1
  --keyStates = {true, true ,1, 1, 1}
  joypad.set(keyStates)
  --joypad.set(keyStates, {})
  --print("down:", joypad.get())
  --print("setTest finished!")
end

function rbFunc()
  local framecount
  framecount = emu.framecount()
  if framecount % (60*3) < 1 then
    print(framecount)
    --print(joypad.read())
    --print(joypad.getup(1))
    setTest(true)
  else
    --setTest(false)
  end
  if framecount % (60*3) == 10 then
    --print(joypad.get()["P1 Button 2"])
    --setTest()
  end
end

emu.registerbefore(rbFunc)
--setTest()